package com.haoze.nurse.enumeration;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

public class OrderTimeTypeEnum {
    private String enumValue;
    private String enumName;
    private final static Map<String,OrderTimeTypeEnum> enumMap = new HashMap();

    /**
     * 临时医嘱
     */
    public final static OrderTimeTypeEnum OpenTime = new OrderTimeTypeEnum("1","开立时间");
    /**
     * 长期医嘱
     */
    public final static OrderTimeTypeEnum StartTime  = new OrderTimeTypeEnum("2","开始时间");
    /**
     * 新开医嘱
     */
    public final static OrderTimeTypeEnum EndTime = new OrderTimeTypeEnum("3","结束时间");

    private OrderTimeTypeEnum(String enumValue, String enumName){
        this.enumValue = enumValue;
        this.enumName = enumName;
    }

    public static OrderTimeTypeEnum fromValue(String enumValue){
        if(enumMap.size() == 0) {
            putSourceEnum();
        }
        return enumMap.get(enumValue);
    }

    private static void  putSourceEnum(){

        Class clazz = OrderTimeTypeEnum.class;
        Field[] fields = clazz.getDeclaredFields();
        OrderTimeTypeEnum enumClass = null;
        for(Field field : fields) {
            if(field.getType().equals(clazz)) {
                try {
                    enumClass = (OrderTimeTypeEnum)field.get(null);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                if(enumClass != null) {
                    enumMap.put(enumClass.getEnumValue(),enumClass);
                }
            }
        }
    }


    public String getEnumValue() {
        return enumValue;
    }

    public String getEnumName() {
        return enumName;
    }
}
